class TarjetasController < ApplicationController
  # GET /tarjetas
  # GET /tarjetas.xml
  def index
    
    @tarjetas = Tarjeta.all(:conditions => {:cliente_id => session[:cliente_id]} )

    respond_to do |format|
    	if @tarjetas == nil
        	flash[:notice] = 'No existen tarjetas asociadas.' 
        	else
      		format.html # index.html.erb
      		format.xml  { render :xml => @tarjetas }
      		end
    	end
    	end

  # GET /tarjetas/1
  # GET /tarjetas/1.xml
  def show
    @tarjeta = Tarjeta.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @tarjeta }
    end
  end

  # GET /tarjetas/new
  # GET /tarjetas/new.xml
  def new
    @tarjeta = Tarjeta.new

    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @tarjeta }
    end
  end
	
  # GET /tarjetas/1/edit
  def edit
    @tarjeta = Tarjeta.find(params[:id])
    
  end
  
    

  # POST /tarjetas
  # POST /tarjetas.xml
  def create
    @tarjeta = Tarjeta.new(params[:tarjeta])

    respond_to do |format|
      if @tarjeta.save
        flash[:notice] = 'La tarjeta fue creada exitosamente.'
        format.html { redirect_to(@tarjeta) }
        format.xml  { render :xml => @tarjeta, :status => :created, :location => @tarjeta }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @tarjeta.errors, :status => :unprocessable_entity }
      end
    end
  end

  # PUT /tarjetas/1
  # PUT /tarjetas/1.xml
  def update
    @tarjeta = Tarjeta.find(params[:id])

    respond_to do |format|
      if @tarjeta.update_attributes(params[:tarjeta])
        flash[:notice] = 'La tarjeta se actualizo correctamente.'
        format.html { redirect_to(@tarjeta) }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @tarjeta.errors, :status => :unprocessable_entity }
      end
    end
  end

  # DELETE /tarjetas/1
  # DELETE /tarjetas/1.xml
  def destroy
    @tarjeta = Tarjeta.find(params[:id])
    @tarjeta.destroy

    respond_to do |format|
      format.html { redirect_to(tarjetas_url) }
      format.xml  { head :ok }
    end
  end
 
end
